//
//  DetailView.m
//  B
//
//  Created by Sunpeng on 15/11/13.
//  Copyright © 2015年 wangzhan. All rights reserved.
//

#import "DetailView.h"

@implementation DetailView
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self addSubviews];
    }
    
    return self;
}

-(void)addSubviews
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    
    flowLayout.minimumLineSpacing = 10;
    
    flowLayout.headerReferenceSize = CGSizeMake(WIDTH, HIGHT * 0.05);
    
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    self.myCollectionView = [[UICollectionView alloc] initWithFrame: CGRectMake(0, 0, WIDTH, HIGHT) collectionViewLayout:flowLayout];
    
    self.myCollectionView.contentInset = UIEdgeInsetsMake(HIGHT * 0.6, 0, 0, 0);
    self.myCollectionView.bounces = NO;
   
    
    [self addSubview:self.myCollectionView];
    
    self.mapImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, -HIGHT * 0.6, WIDTH, HIGHT*0.25)];
    [self.myCollectionView addSubview:self.mapImage];
    self.mapImage.image = [UIImage imageNamed:@"ditu"];
    //[self.mapImage release];
    
    self.user_avatar = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH *0.15, WIDTH * 0.15)];
    self.user_avatar.backgroundColor = [UIColor lightGrayColor];
    self.user_avatar.layer.masksToBounds = YES;
    self.user_avatar.layer.cornerRadius = self.user_avatar.width/2;
    self.user_avatar.layer.borderWidth = 3;
    self.user_avatar.layer.borderColor = [[UIColor whiteColor]CGColor];
    self.user_avatar.center = self.myCollectionView.center;
    self.user_avatar.y = -HIGHT * 0.4;
    [self.myCollectionView addSubview:self.user_avatar];
    
    
    self.user_name = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, WIDTH * 0.4 ,HIGHT * 0.05 )];
    self.user_name.center = self.user_avatar.center;
    self.user_name.y = self.user_avatar.y + self.user_avatar.height;
    self.user_name.textAlignment = NSTextAlignmentCenter;
    self.user_name.font = [UIFont systemFontOfSize:12];
    self.user_name.textColor = [UIColor lightGrayColor];
    
    [self.myCollectionView addSubview:self.user_name];
    
    
    self.name = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HIGHT*0.05)];
    self.name.center = self.user_name.center;
    self.name.textAlignment = NSTextAlignmentCenter;
    self.name.y = self.user_name.y + self.user_name.height;
    [self.myCollectionView addSubview:self.name];
   
    
    UIImageView *bgImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH * 0.9, HIGHT * 0.1)];
    bgImage.center = self.name.center;
    bgImage.y = self.name.y + self.name.height;
    bgImage.image = [UIImage imageNamed:@"user_info_fav_bg"];
    [self.myCollectionView addSubview:bgImage];
    
    
    UILabel *mileageLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, WIDTH * 0.3, HIGHT*0.05)];
    mileageLabel.center = bgImage.center;
    mileageLabel.y = bgImage.y;
    mileageLabel.text = @"里程";
    mileageLabel.textAlignment = NSTextAlignmentCenter;
    mileageLabel.font = [UIFont boldSystemFontOfSize:12];
    [self.myCollectionView addSubview:mileageLabel];
  
    
    self.mileage = [[UILabel alloc]initWithFrame:CGRectMake(mileageLabel.x, mileageLabel.y + mileageLabel.height, mileageLabel.width*1, mileageLabel.height)];
    self.mileage.textColor = [UIColor lightGrayColor];
    self.mileage.textAlignment = NSTextAlignmentCenter;
    self.mileage.font = [UIFont systemFontOfSize:12];
    [self.myCollectionView addSubview:self.mileage];
    
    
    UILabel *recommendationsLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.mileage.x + self.mileage.width, bgImage.y, WIDTH * 0.3, HIGHT*0.05)];
    recommendationsLabel.text = @"喜欢";
    recommendationsLabel.font = [UIFont boldSystemFontOfSize:12];
    recommendationsLabel.textAlignment = NSTextAlignmentCenter;
    [self.myCollectionView addSubview:recommendationsLabel];
    
    
    self.recommendations = [[UILabel alloc]initWithFrame:CGRectMake(recommendationsLabel.x, recommendationsLabel.y + recommendationsLabel.height, recommendationsLabel.width, mileageLabel.height)];
    self.recommendations.font = [UIFont systemFontOfSize:12];
    self.recommendations.textColor = [UIColor lightGrayColor];
    self.recommendations.textAlignment = NSTextAlignmentCenter;
    [self.myCollectionView addSubview:self.recommendations];
   
    
    self.first_day = [[UILabel alloc]initWithFrame:CGRectMake(bgImage.x, bgImage.y, WIDTH * 0.3, HIGHT*0.05)];
    self.first_day.text = @"日期";
    self.first_day.font = [UIFont boldSystemFontOfSize:12];
    self.first_day.textAlignment = NSTextAlignmentCenter;
    [self.myCollectionView addSubview:self.first_day];
    
    
    self.day_count = [[UILabel alloc]initWithFrame:CGRectMake(self.first_day.x, self.first_day.y + self.first_day.height, self.first_day.width, self.first_day.height)];
    self.day_count.textColor = [UIColor lightGrayColor];
    self.day_count.textAlignment = NSTextAlignmentCenter;
    self.day_count.font = [UIFont systemFontOfSize:12];
    [self.myCollectionView addSubview:self.day_count];
    
    
}

-(void)setDetailViewData:(DetailModel *)model{
    [self.user_avatar sd_setImageWithURL:[NSURL URLWithString:model.user_avatar] placeholderImage:nil];
    self.user_name.text = model.user_name;
    self.name.text = model.name;
    self.day_count.text = [NSString stringWithFormat:@"%@天", model.day_count];
    self.mileage.text = [NSString stringWithFormat:@"%dkm",  [model.mileage intValue]];
    self.recommendations.text = [NSString stringWithFormat:@"%@", model.recommendations];
    self.first_day.text = model.first_day;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
